package trunk.gui;

import trunk.res.R;
import trunk.control.Control;

import javax.swing.*;
import java.awt.*;

/**
 * MicrocodePanel used to contain the micro code generate in running time
 * Created by IntelliJ IDEA.
 * User: yipeipei
 * Date: 12/13/11
 * Time: 7:56 PM
 * To change this template use File | Settings | File Templates.
 */
public class MicrocodePanel extends JPanel {
    private StringBuffer microCodeBuffer = null;    //keep the micro code in a string buffer for the micro code changes
    private TextArea textArea = null;   //to display the micro code
    private TextArea output = null;
    
    public MicrocodePanel() {
        super(true);    //true for enable double buffer
        this.setBounds(
                R.attribute.SIM_PANEL_WIDTH,
                R.attribute.INSTRUCTION_PANEL_HEIGHT + R.attribute.PARAMETER_PANEL_HEIGHT + 50,
                R.attribute.MICROCODE_PANEL_WIDTH,
                R.attribute.MICROCODE_PANEL_HEIGHT - 50);    //set a fixed location in its container
        this.setBorder(R.attribute.BORDER);

        this.setLayout(new BorderLayout());

        initialize();

        this.setVisible(true);
    }
    public MicrocodePanel(int x, int y, int weith, int hight) {
        super(true);    //true for enable double buffer
        this.setBounds(x, y, weith, hight);
                
        this.setBorder(R.attribute.BORDER);

        this.setLayout(new BorderLayout());
        
        this.output = new TextArea("Instruction: \n", 1, 30, TextArea.SCROLLBARS_NONE);
    //    this.output = new TextArea("Instruction: ");
        this.output.setEditable(false);
        this.add(output);
        
        this.setVisible(true);
        
    }

    /**
     * initializeAuxiliary the variable for this panel
     */
    public void initialize() {
        this.microCodeBuffer = new StringBuffer("Micro Code goes here\n");
        this.textArea = new TextArea(microCodeBuffer.toString(), 19, 23, TextArea.SCROLLBARS_NONE);
        this.textArea.setEditable(false);
        this.add(textArea);
        
        
     }

    public void printInstruction(String micro) {
        
         this.textArea.append(micro);
    }
    public void printoutputInstruction(String micro) {
         
         this.output.append(micro);
    }
}
